home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / BEHAVIOR / BHVR / COMBHVR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  4.2 KB  |  148 lines

  1. /* $Id: COMBhvr.cpp 1.9 1997/04/05 02:39:27 damien Exp $ */
  2.  
  3. ////////////////////////////////////////////////////////////////////////
  4. //   Tree Behavior Example : ?????                                    //
  5. //--------------------------------------------------------------------//
  6. //   Implementation of the Behavior Interface                         //
  7. //////////////////////////////////////////////////////////////////////// 
  8.  
  9.  
  10. #ifndef __COM_BHVR__
  11. #include "COMBhvr.h"
  12. #endif
  13.  
  14. #ifndef __BHVR_DLL__
  15. #include "BhvrDLL.h"
  16. #endif
  17.  
  18. #ifndef __I3DSHSCN__
  19. #include "I3DShScn.h"
  20. #endif
  21.  
  22. #ifndef __3DCOFAIL__
  23. #include "3DCoFail.h"
  24. #endif
  25.  
  26. #undef INTERFACE
  27. #define INTERFACE Behavior
  28. // Constructor / Destructor of the C++ Object :
  29. Behavior::Behavior() {
  30.   fCRef=0; // Reference Counter
  31.   // Data initialisation :
  32.   *fData.fNameObject1=0;
  33.   *fData.fNameObject2=0;
  34.   fData.fRelPos = 0.5; // 50% , at the middle of the two objects
  35.   }
  36.   
  37. Behavior::~Behavior() {
  38.   global_count_Obj--; 
  39.   }
  40.   
  41. // IUnknown Interface :
  42. HRESULT Behavior::QueryInterface(THIS_ REFIID riid,LPVOID* ppvObj) {
  43.   *ppvObj=NULL;
  44.   
  45.   // The Behavior knows the interfaces of the parent Objects
  46.   if (IsEqualIID(riid, IID_IUnknown))
  47.     *ppvObj=(LPVOID)this;
  48.   else if (IsEqualIID(riid, IID_I3DExTreeBehavior))
  49.     *ppvObj=(LPVOID)this;
  50.   else if (IsEqualIID(riid, IID_I3DExDataExchanger))
  51.     *ppvObj=(LPVOID)this;
  52.   else if (IsEqualIID(riid, IID_I3DExtension))
  53.     *ppvObj=(LPVOID)this;
  54.     
  55.   // we must add reference if we return an interface
  56.   if (*ppvObj!=NULL) {
  57.     ((LPUNKNOWN)*ppvObj)->AddRef();
  58.     return NOERROR;
  59.     }
  60.   else {
  61.     return ResultFromScode(E_NOINTERFACE);
  62.     }
  63.   }
  64.  
  65. ULONG Behavior::AddRef(THIS) {
  66.   return fCRef++;
  67.   }
  68.   
  69. ULONG Behavior::Release(THIS) {
  70.   ULONG UnreleaseObject=fCRef--;
  71.   
  72.   if (fCRef==0)
  73.      delete this; // No reference left, so destroy the object
  74.   
  75.   return UnreleaseObject;
  76.   // local variable used, because fCRef can be destroyed before.
  77.   }
  78.   
  79. // I3DExtension methods :
  80. I3DExtension* Behavior::Clone(THIS) {
  81.   Behavior* theClone = new Behavior;
  82.   if (theClone) {
  83.     theClone->AddRef();
  84.     theClone->fData=fData; // copy the BehaviorData
  85.     }                               
  86.   return theClone;
  87.   }   
  88.  
  89. HRESULT Behavior::ShellUtilitiesInit(THIS_ IShUtilities* shellUtilities) {
  90.   InitCoFailure(shellUtilities);
  91.   return NOERROR;
  92.   }
  93.  
  94. // I3DExDataExchanger methods :
  95. ExtensionDataMap* Behavior::GetExtensionDataMap(THIS) {
  96.   return NULL;
  97.   }
  98.  
  99. void* Behavior::GetExtensionDataBuffer(THIS) {
  100.   return &fData; // used by the shell to set the new parameters
  101.   }
  102.   
  103. HRESULT Behavior::ExtensionDataChanged(THIS) {
  104.   return NOERROR;
  105.   }
  106.  
  107. HRESULT Behavior::HandleEvent(THIS_ ULONG SourceID) {
  108.   return ResultFromScode(E_NOTIMPL);
  109.   }
  110.  
  111. short Behavior::GetResID(THIS) {
  112.   return 142; // this is the view ID in the resource file.
  113.   }
  114.                                                                             
  115. // I3DExTreeBehavior methods :
  116. HRESULT Behavior::Apply(THIS_ I3DShTreeElement* tree) {
  117.   TREETRANSFORM3D tr1;
  118.   TREETRANSFORM3D tr2;
  119.   TREETRANSFORM3D tr;
  120.   I3DShTreeElement *tree1,*tree2;
  121.   I3DShScene *scene;
  122.   // Get the scene
  123.   scene = tree->GetScene();
  124.   if (!scene) return NOERROR; // abort any modifications if you can not get the scene
  125.  
  126.   // Search tree element 1 by name
  127.   tree1 = scene->GetTreeElementByName(fData.fNameObject1);
  128.   if (!tree1) return NOERROR; // abort because object 1 not found
  129.   tree1->GetGlobalTransform8(&tr1);
  130.  
  131.   // Search tree element 2 by name
  132.   tree2 = scene->GetTreeElementByName(fData.fNameObject2);
  133.   if (!tree2) return NOERROR; // abort because object 2 not found
  134.   tree2->GetGlobalTransform8(&tr2);
  135.  
  136.   // Set the new position of tree
  137.   tree->GetGlobalTransform8(&tr);
  138.   tr.fT[0] = tr1.fT[0] + (tr2.fT[0] - tr1.fT[0]) * fData.fRelPos ;
  139.   tr.fT[1] = tr1.fT[1] + (tr2.fT[1] - tr1.fT[1]) * fData.fRelPos ;
  140.   tr.fT[2] = tr1.fT[2] + (tr2.fT[2] - tr1.fT[2]) * fData.fRelPos ;
  141.   tree->SetGlobalTransform8(&tr);
  142.   return NOERROR;
  143.   }
  144.  
  145. HRESULT Behavior::SetGlobalTransform (THIS_ I3DShTreeElement *atree,const MATRIX3D *RR,const VECTOR3D *TT,short mode) {
  146.     return ResultFromScode(E_NOTIMPL);
  147.     }
  148.